from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-28 14:06:24.377571
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 28, Jan, 2022
Time: 14:06:29
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.8727
Nobs: 550.000 HQIC: -48.3024
Log likelihood: 6425.19 FPE: 7.99607e-22
AIC: -48.5780 Det(Omega_mle): 6.79905e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.349469 0.069861 5.002 0.000
L1.Burgenland 0.106140 0.042446 2.501 0.012
L1.Kärnten -0.110818 0.022035 -5.029 0.000
L1.Niederösterreich 0.197527 0.088723 2.226 0.026
L1.Oberösterreich 0.131187 0.087680 1.496 0.135
L1.Salzburg 0.255016 0.044858 5.685 0.000
L1.Steiermark 0.034567 0.059186 0.584 0.559
L1.Tirol 0.098814 0.047757 2.069 0.039
L1.Vorarlberg -0.072306 0.042199 -1.713 0.087
L1.Wien 0.017708 0.078035 0.227 0.820
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054334 0.151449 0.359 0.720
L1.Burgenland -0.040746 0.092017 -0.443 0.658
L1.Kärnten 0.040766 0.047769 0.853 0.393
L1.Niederösterreich -0.203696 0.192340 -1.059 0.290
L1.Oberösterreich 0.455014 0.190079 2.394 0.017
L1.Salzburg 0.282699 0.097247 2.907 0.004
L1.Steiermark 0.116801 0.128306 0.910 0.363
L1.Tirol 0.305179 0.103530 2.948 0.003
L1.Vorarlberg 0.023963 0.091482 0.262 0.793
L1.Wien -0.024718 0.169169 -0.146 0.884
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195458 0.035520 5.503 0.000
L1.Burgenland 0.090677 0.021582 4.202 0.000
L1.Kärnten -0.007336 0.011204 -0.655 0.513
L1.Niederösterreich 0.236302 0.045111 5.238 0.000
L1.Oberösterreich 0.168265 0.044581 3.774 0.000
L1.Salzburg 0.038260 0.022808 1.677 0.093
L1.Steiermark 0.025603 0.030093 0.851 0.395
L1.Tirol 0.080623 0.024282 3.320 0.001
L1.Vorarlberg 0.055736 0.021456 2.598 0.009
L1.Wien 0.118146 0.039676 2.978 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118290 0.035677 3.316 0.001
L1.Burgenland 0.043341 0.021677 1.999 0.046
L1.Kärnten -0.013912 0.011253 -1.236 0.216
L1.Niederösterreich 0.172080 0.045310 3.798 0.000
L1.Oberösterreich 0.335349 0.044778 7.489 0.000
L1.Salzburg 0.099822 0.022909 4.357 0.000
L1.Steiermark 0.109138 0.030226 3.611 0.000
L1.Tirol 0.090790 0.024389 3.723 0.000
L1.Vorarlberg 0.060513 0.021551 2.808 0.005
L1.Wien -0.015706 0.039852 -0.394 0.694
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125524 0.067342 1.864 0.062
L1.Burgenland -0.048092 0.040916 -1.175 0.240
L1.Kärnten -0.045533 0.021240 -2.144 0.032
L1.Niederösterreich 0.140631 0.085524 1.644 0.100
L1.Oberösterreich 0.167828 0.084519 1.986 0.047
L1.Salzburg 0.283546 0.043241 6.557 0.000
L1.Steiermark 0.058725 0.057052 1.029 0.303
L1.Tirol 0.154859 0.046035 3.364 0.001
L1.Vorarlberg 0.094118 0.040678 2.314 0.021
L1.Wien 0.071891 0.075221 0.956 0.339
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080442 0.052481 1.533 0.125
L1.Burgenland 0.023659 0.031887 0.742 0.458
L1.Kärnten 0.053302 0.016553 3.220 0.001
L1.Niederösterreich 0.193043 0.066651 2.896 0.004
L1.Oberösterreich 0.329606 0.065868 5.004 0.000
L1.Salzburg 0.033713 0.033699 1.000 0.317
L1.Steiermark 0.003233 0.044462 0.073 0.942
L1.Tirol 0.120222 0.035876 3.351 0.001
L1.Vorarlberg 0.065925 0.031701 2.080 0.038
L1.Wien 0.098633 0.058622 1.683 0.092
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174280 0.063498 2.745 0.006
L1.Burgenland 0.003220 0.038580 0.083 0.933
L1.Kärnten -0.065355 0.020028 -3.263 0.001
L1.Niederösterreich -0.110202 0.080642 -1.367 0.172
L1.Oberösterreich 0.214950 0.079695 2.697 0.007
L1.Salzburg 0.052457 0.040773 1.287 0.198
L1.Steiermark 0.250789 0.053795 4.662 0.000
L1.Tirol 0.497493 0.043407 11.461 0.000
L1.Vorarlberg 0.065883 0.038356 1.718 0.086
L1.Wien -0.079803 0.070928 -1.125 0.261
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.157190 0.070227 2.238 0.025
L1.Burgenland -0.004527 0.042669 -0.106 0.915
L1.Kärnten 0.062136 0.022150 2.805 0.005
L1.Niederösterreich 0.180815 0.089188 2.027 0.043
L1.Oberösterreich -0.066683 0.088140 -0.757 0.449
L1.Salzburg 0.205536 0.045093 4.558 0.000
L1.Steiermark 0.139090 0.059496 2.338 0.019
L1.Tirol 0.056373 0.048007 1.174 0.240
L1.Vorarlberg 0.143171 0.042420 3.375 0.001
L1.Wien 0.130223 0.078444 1.660 0.097
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.395166 0.040966 9.646 0.000
L1.Burgenland -0.002859 0.024890 -0.115 0.909
L1.Kärnten -0.020755 0.012921 -1.606 0.108
L1.Niederösterreich 0.202403 0.052027 3.890 0.000
L1.Oberösterreich 0.241922 0.051416 4.705 0.000
L1.Salzburg 0.033442 0.026305 1.271 0.204
L1.Steiermark -0.017894 0.034706 -0.516 0.606
L1.Tirol 0.086809 0.028004 3.100 0.002
L1.Vorarlberg 0.051250 0.024745 2.071 0.038
L1.Wien 0.034222 0.045759 0.748 0.455
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035182 0.102280 0.166351 0.133512 0.093251 0.081087 0.029235 0.211954
Kärnten 0.035182 1.000000 -0.025558 0.133551 0.046888 0.086107 0.444162 -0.068617 0.093144
Niederösterreich 0.102280 -0.025558 1.000000 0.310331 0.124965 0.267877 0.068249 0.156496 0.282033
Oberösterreich 0.166351 0.133551 0.310331 1.000000 0.214928 0.292898 0.170792 0.134512 0.236505
Salzburg 0.133512 0.046888 0.124965 0.214928 1.000000 0.124683 0.089790 0.103719 0.126758
Steiermark 0.093251 0.086107 0.267877 0.292898 0.124683 1.000000 0.134425 0.105362 0.029725
Tirol 0.081087 0.444162 0.068249 0.170792 0.089790 0.134425 1.000000 0.063184 0.151298
Vorarlberg 0.029235 -0.068617 0.156496 0.134512 0.103719 0.105362 0.063184 1.000000 -0.004630
Wien 0.211954 0.093144 0.282033 0.236505 0.126758 0.029725 0.151298 -0.004630 1.000000